Latest update: July 2013
It is good idea to change the SSID and the network key to ensure a safe communication via Wireless LAN. This tutorial will explain how to set the SSID and network key of your FlashAir device.
In this tutorial, we will create a web application which can configure the SSID and network key of your FlashAir device. You can use command.cgi to get the current SSID and network key, and config.cgi to set the SSID and network key.
NOTE: It is not possible to get or set the network key if the FlashAir is configured to the Station mode. Please configure the card to the Access Point mode.
We need MASTERCODE to change the configuration of the FlashAir. MASTERCODE is a kind of password to restrict access to the configuration file to the authorized users.
Usually the MASTERCODE is the MAC address of the device that the FlashAir was set up with if we use the official Browser Utility or smartphone apps. We will use an API to get the MAC address and use it as the MASTERCODE for this sample program.
We assume the FlashAir card is initialized with the official tools, and we will use the same device used for the initialization as a target device in this tutorial.
As well as we do in the previous tutorials, the HTML file will consists of several elements: loading external JavaScript file, preparing tags as a place holder to show MASTERCODE (MAC address), SSID and network key, and a button to apply new configuration to the FlashAir.
NOTE: We have displayed the MASTERCODE in this tutorial application to demonstrate how the
FlashAir
device works. This information is provided for tutorial purposes only. For security
reasons,
we highly discourage you from publicly displaying your MASTERCODE. Also, password should be
hidden
by masking characters like
********
.
We will save the HTML file as
/SD_WLAN/Config.htm
on the FlashAir.
<!doctype html>
<html>
<head>
<title>FlashAir</title>
<meta charset="UTF-8">
<title>Flash Air Configuration</title>
<script type="text/javascript" src="/SD_WLAN/js/jquery.js"></script>
<script type="text/javascript" src="/SD_WLAN/js/config.js"></script>
</head>
<body>
<div id="header">
<h1>header</h1>
</div>
<hr>
<div><a href="/">Back to TopPage</a></div>
<div id="formarea">
Mastercode<br>
<span id="mastercode"></span><br>
SSID<br>
<input name="appssid" id="appssid" type="text" value="" maxlength="32" /><br>
Password<br>
<input name="appnetworkkey" id="appnetworkkey" type="text" value="" maxlength="63"/><br>
<button id="submit">submit</button><span id="result"></span>
</div>
<hr>
<div id="footer">
footer
</div>
</body>
</html>
id
attribute in order to access them from the JavaScript program.
type="password"
.
When the page is loaded, you will get the MASTERCODE, APPSSID, and APPNETWORKKEY after command.cgi is called.
When you call
config.cgi on click the button, you can set new
values for the APPSSID and APPNETWORKKEY.
If this command is successful,
SUCCESS
is returned.
Otherwise,
ERROR
is returned. The return value will be shown on screen.
// JavaScript Document
function getMasterCode(){
var url="/command.cgi?op=106";
$.get(url,function(data){
$('#mastercode').text(data);
mastercode=data;
});
}
function getSSID(){
var url="/command.cgi?op=104";
$.get(url,function(data){
$('#appssid').val(data);
});
}
function getAPPNETWORKKEY(){
var url="/command.cgi?op=105";
$.get(url,function(data){
$('#appnetworkkey').val(data);
});
}
function setParams(){
var datetime = new Date();
var url="/config.cgi?MASTERCODE="+mastercode
+"&APPSSID="+$("#appssid").val()
+"&APPNETWORKKEY="+$("#appnetworkkey").val()
+"&TIME="+datetime.getTime();
$.get(url,function(data){
$('#result').text(data);
});
}
//Document Ready
$(function() {
getMasterCode();
getSSID();
getAPPNETWORKKEY();
$("#submit").click(setParams);
});
getMasterCode()
function. Inside this function, a call is made to
command.cgi?op=106
and the response is stored for later use.
getSSID()
function. Inside this function, a call is made to
command.cgi?op=104.
getAPPNETWORKKEY()
function. Inside this function, a call is made to
command.cgi?op=105.
setParams()
function (line 21) to a click event.
Save the program on the FlashAir, and open your web browser on your PC or smartphone connected to the FlashAir. Input the following URL into the URL box of your web browser.
http://flashair/SD_WLAN/Config.htm
The current configurations will be shown on the screen. (Left image.) You can modify the
configuration
as you edit the values and click
submit
button. If this command is successful,
SUCCESS
will be shown. (Right image.)
Note that wireless connection will be disconnected after configuration command is
issued. You
need to reconnect your device to the FlashAir with the new SSID.
web_tutorial_06.zip (2KB)
All sample code on this page is licensed under BSD 2-Clause License